﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Rud.Holmgren.Tabulex3000.Util
{
    class UiControlsProgressManager : IProgressManager
    {
        private ProgressBar bar;
        private TextBlock text;

        public UiControlsProgressManager(ProgressBar bar, TextBlock text)
        {
            this.bar = bar;
            this.text = text;
        }

        public void SetState(bool visible, string caption)
        {
            if (!bar.Dispatcher.CheckAccess())
            {
                bar.Dispatcher.BeginInvoke(() => SetState(visible, caption));
                return;
            }

            bar.IsIndeterminate = true;
            bar.Opacity = visible ? 1 : 0;
            text.Opacity = bar.Opacity;

            if (visible)
            {
                text.Text = caption;
            }
        }
    }
}
